import { _decorator, Component, EventTouch, find, Label, Node, Slider, Vec2, Vec3 } from 'cc';
import { Global } from '../../Util/Global';
import SoundCtrl from '../../Ctrl/SoundCtrl';
const { ccclass, property } = _decorator;

@ccclass('ScaleViewUI')
export class ScaleViewUI extends Component {

    slider: Slider = null;
    txt: Label = null;
    start() {
        this.slider = this.getComponent(Slider);
        this.txt = find('Handle/txt', this.node).getComponent(Label);
    }

    scale = new Vec3(1, 1, 1);
    OnSlideScaleView() {
        Global.CameraOrthoHeight = Global.designScreenSize.height * (2 - this.slider.progress) / 2;
        let n = Global.CameraOrthoHeight / Global.designScreenSize.height * 2;
        let cur = this.txt.string;
        let neww = Global.CameraOrthoScale.toFixed(2) + 'x';
        if (neww != cur) {
            SoundCtrl.playEffect('mouserelease1', 0.1);
        }
        this.scale.x = n;
        this.scale.y = n;
        Global.gameManager.playerCtrl.node.scale = this.scale;

    }

    protected update(dt: number): void {

        this.txt.string = Global.CameraOrthoScale.toFixed(2) + 'x';
        this.slider.progress = 2 - Global.CameraOrthoScale;
    }
}


